package com.music.controller;

import com.music.dto.Result;
import com.music.entity.SongListType;
import com.music.service.SongListTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/songlisttype")
public class SongListTypeController {

    @Autowired
    private SongListTypeService songListTypeService;

    @GetMapping("/root")
    public @ResponseBody
    Result getRootSongListType(){
        List<SongListType> rootSongListTypeList = songListTypeService.getRootSongListType();
        if(!rootSongListTypeList.isEmpty()){
            return new Result().ok(rootSongListTypeList);
        }
        return new Result().fail(0,"没有相关数据");
    }

    @GetMapping("/sub")
    public @ResponseBody
    Result getSubSongListType(@RequestParam Integer songListTypeId){
        List<SongListType> subSongListTypeList = songListTypeService.getSubSongListTypeByParentTypeId(songListTypeId);
        if(!subSongListTypeList.isEmpty()){
            return new Result().ok(subSongListTypeList);
        }
        return new Result().fail(0,"没有相关数据");
    }
}
